<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 $role = ArticleflowHelper::getUserRole();
  $user = & JFactory::getUser();
  $uid = $user->get('id');
?>
<?php defined('_JEXEC') or die('Restricted access'); ?>

<?php JHTML::_('behavior.tooltip');
ArticleflowHelper::Previous();
date_default_timezone_set('Asia/Krasnoyarsk');
?>
<div id="editcell">
    <form action="index.php" method="post" name="adminForm">
	<table class="adminlist">
	<thead>
		<tr>
			<th width="5">
				<?php echo JText::_( 'STT' ); ?>
			</th>
			<th width="20">
				<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $this->items ); ?>);" />
			</th>
                        <th class="title">
				<?php echo JText::_('Title'); ?>
			</th>
                         <th class="title">
				<?php echo JText::_('Chủ đề chính'); ?>
			</th>
                        <th class="title">
				<?php echo JText::_('Category'); ?>
			</th>
			<th width="15%" nowrap="nowrap">
				<?php echo JText::_('Thời gian khởi tạo' ); ?>
			</th>

			<th width="5%" nowrap="nowrap">
				<?php echo JText::_('Người tạo bài' ); ?>
			</th>
			<th width="10%" nowrap="nowrap">
				<?php echo JText::_('Thời gian thay đổi' ); ?>
			</th>
			<th width="10%" nowrap="nowrap">
				<?php echo JText::_('Người thay đổi' ); ?>
			</th>
			<th width="5%" nowrap="nowrap">
				<?php echo JText::_('ID' ); ?>
			</th>
<!--                       <th width="10%" nowrap="nowrap">
				<?php //echo JText::_('Published' ); ?>
			</th>-->
		</tr>
	</thead>
<!--        <tfoot>
		<tr>
			<td colspan=12">
				<?php //echo $this->pagination->getListFooter(); ?>
			</td>
		</tr>
	</tfoot>-->
        <tbody>
        <?php
	$k = 0;
	for ($i=0, $n=count( $this->items ); $i < $n; $i++)
	{
		$row = &$this->items[$i];

		$link 	= JRoute::_( 'index.php?option=com_articleflow&view=history&task=edit&cid[]='. $row->id );

		$checked 	= JHTML::_('grid.checkedout',   $row, $i );

		//$published 	= JHTML::_('grid.published', $row, $i );

                $img 	= $row->state ? 'tick.png' : 'publish_x.png';
		$task 	= $row->state ? 'unpublish' : 'publish';
		$alt 	= $row->state ? JText::_( 'Published' ) : JText::_( 'Unpublished' );
		$action = $row->state ? JText::_( 'Unpublish Item' ) : JText::_( 'Publish item' );

//		$state = '
//		<a href="javascript:void(0);" onclick="return listItemTask(\'cb'. $i .'\',\''.$task .'\')" title="'. $action .'">
//		<img src="images/'. $img .'" border="0" alt="'. $alt .'" /></a>'
//		;

                $state = '

		<img src="images/'. $img .'" border="0" alt="'. $alt .'" />'
		;

		?>
		<tr class="<?php echo "row$k"; ?>">
			<td>
				<?php echo $this->pagination->getRowOffset( $i ); ?>
			</td>
			<td>
				<?php echo $checked; ?>
			</td>

			<td align="center">

                            <span class="editlinktip hasTip" title="<?php echo JText::_( 'Edit ArticleFlow' );?>::<?php echo $this->escape($row->title); ?>">
					<?php
                                        //ToDo ........
                                            if($role==0){
                                                if(($uid != $row->assigned_user)|| ($row->state==1 || $row->state==2))
                                                {
                                                    echo $this->escape($row->title);
                                                }else {?>
                                                    <a href="<?php echo $link; ?>"><?php echo $this->escape($row->title); ?></a>
                                        <?php   }

                                        }
                                        else{
                                ?>
                                         <a href="<?php echo $link; ?>"><?php echo $this->escape($row->title); ?></a>
                                        <?php

                                        }

                                        //End..
                                        ?>

				</span>
			</td>
                        <td align="center">
				<?php echo $row->secname?>
			</td>
                        <td align="center">
				<?php echo $row->catename?>
			</td>
                        <td align="center">
                            <?php echo date('d-m-Y h:mA', strtotime($row->created));?>
				
			</td>
			<td align="center">
				<?php
                                    $model = $this->getModel();
                                    $result = $model->getUserNameByCreated($this->items[$i]->created_by);

                                echo $result->name;
                                    ?>

			</td>
			<td align="center">
				<?php echo date('d-m-Y h:mA', strtotime($row->modified));?>
			</td>

			<td align="center">
				<?php

                                    if($this->items[$i]->modified_by == null)
                                    {
                                        echo "X";
                                    }
                                    else
                                    {
                                         $model = $this->getModel();
                                         $result = $model->getUserNameByModified($this->items[$i]->modified_by);
                                         echo $result->name;
                                    }



                                    ?>
			</td>
			<td align="center">
				<?php echo $row->id; ?>
			</td>
<!--                        <td align="center">
				<?php //echo $state; ?>
			</td>-->

		</tr>
		<?php
		$k = 1 - $k;
	}
        
	?>
	</tbody>
    </table>
        <input type="hidden" name="option" value="com_articleflow" />
        <input type="hidden" name="cid[]" value="<?php echo $this->items[0]->content_temp_id; ?>" />
        <input type="hidden" name="view" value="history" />
        <input type="hidden" name="task" value="edit" />
    <?php echo JHTML::_('form.token'); ?>
</form>
</div>